package com.example.ycdyus.dailyfruit.ui;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import com.example.ycdyus.dailyfruit.BaseApp;
import com.example.ycdyus.dailyfruit.R;
import com.example.ycdyus.dailyfruit.fragment.CategoryFragment;
import com.example.ycdyus.dailyfruit.fragment.GuoshiFragment_;
import com.example.ycdyus.dailyfruit.fragment.HomeFragment;
import com.example.ycdyus.dailyfruit.fragment.MyFragment;
import com.example.ycdyus.dailyfruit.fragment.MyFragment_;
import com.example.ycdyus.dailyfruit.fragment.ShopFragment;
import com.example.ycdyus.dailyfruit.utils.AppManager;
import com.example.ycdyus.dailyfruit.utils.FragmentTabUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener{

    /**
     * 处理返回操作的变量
     */
    private long lastBackTime;

    /**
     * 添加Fragment
     */
    private List<Fragment> list = new ArrayList<>();
    public static RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        /**
         * 检查是否更新
         */
//        Utils.checkVersion(MainActivity.this);
        initView();
        initData();
    }

    /**
     * 初始化数据
     */
    private void initData() {
        list.add(new HomeFragment());
        list.add(new CategoryFragment());
        list.add(new MyFragment_());
        list.add(new ShopFragment());
        list.add(new GuoshiFragment_());
        new FragmentTabUtils(getSupportFragmentManager(), list, R.id.fragment_main_container, rg, this);
    }

    /**
     * 初始化控件
     */
    private void initView() {
        rg = (RadioGroup) this.findViewById(R.id.rg_main_bottom_tab);
    }

    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if(currentTime-lastBackTime>1*1000){
            lastBackTime = currentTime;
            BaseApp.showToast(getString(R.string.mian_back_str));
        }else{
            AppManager.getAppManager().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {
        switch (index)
        {
            case 0:
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
        }
    }
}
